# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=virt-firmware
pkgver=23.5
pkgrel=1
pkgdesc="Collection of tools for edk2 firmware images"
arch=(any)
url="https://gitlab.com/kraxel/virt-firmware"
license=(GPL2)
depends=(
  python
  python-crc32c  # undeclared runtime dependency: https://gitlab.com/kraxel/virt-firmware/-/issues/4
  python-cryptography
  python-pefile
  python-setuptools
)
makedepends=(
  python-build
  python-installer
  python-wheel
)
checkdepends=(python-pytest)
source=(https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz)
sha512sums=('c86d1148a5c34418045b04cc728f33fcf542d2d39ee7d6f8f0932fb8021859ecb5f2fe44803a657d0ae69865c3f67823dadb9dfb52038bcf9378cde7128ee475')
b2sums=('83b8616f199b007e88c4055c2b8eb7fb0260348fc9cafdd256c6150dcc128ffe33d89c7d19eab1ffbb4b3a2780054f912f986fa0fa4ccd3e4da703bd975ee2b5')

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $pkgname-$pkgver
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"

  pytest -vv tests/tests.py
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 man/virt-*.1 -t "$pkgdir/usr/share/man/man1/"
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
